using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;

namespace DOTS.DOD.LESSON3
{
    readonly partial struct RotateAndMoveAspect : IAspect
    {
        readonly RefRW<LocalTransform> mLocalTransform;
        readonly RefRO<RotateAndMoveSpeed> mSpeed;

        public void Move(double elapsedTime)
        {
            mLocalTransform.ValueRW.Position.y = (float) math.sin(elapsedTime * mSpeed.ValueRO.MoveSpeed);
        }

        public void Rotate(float deltaTime)
        {
            mLocalTransform.ValueRW = mLocalTransform.ValueRO.RotateY(mSpeed.ValueRO.RotateSpeed * deltaTime);
        }

        public void RotateAndMove(double elapsedTime, float deltaTime)
        {
            mLocalTransform.ValueRW.Position.y = (float) math.sin(elapsedTime * mSpeed.ValueRO.MoveSpeed);
            mLocalTransform.ValueRW = mLocalTransform.ValueRO.RotateY(mSpeed.ValueRO.RotateSpeed * deltaTime);
        }
    }
}